<?php

abstract class Soul_Template_Html_Grid_Head_Base extends Soul_Template_Html_Container {

    private $_grid = NULL;
	private $_text = '';
	private $_sortField = '';
	
    public function setGrid($value) {
        $this->_grid = $value;
        return $this;
    }

    public function getGrid() {
        return $this->_grid;
    }

    protected function getSortUrl() {
        if ($this->getGrid()->getSortField() == $this->getSortField()) {
            $direction = $this->getGrid()->getSortDirection() == 'asc' ? 'desc' : 'asc';
        } else {
            $direction = 'asc';
        }
        $result = str_replace('{field}', $this->getSortField(), $this->getGrid()->getSortUrlFormat());
        return str_replace('{direction}', $direction, $result);
    }
    
    public function getText(){
    	return $this->_text;
    }
    
    public function setText($value){
    	$this->_text = $value;
    	return $this;
    }
    
    public function getSortField(){
    	return $this->_sortField;
    }
    
    public function setSortField($value){
    	$this->_sortField = $value;
    	return $this;
    }    

    public function getAttributeHtml() {
        if ($this->getSortField()) {
            $this->addClass('sort');
            if ($this->getGrid()->getSortField() == $this->getSortField()) {
                $this->addClass($this->getGrid()->getSortDirection());
            }
        }

        return parent::getAttributeHtml();
    }
    
    public function renderBegin(){
        return '<th'.$this->getAttributeHtml().'>';
    }
    
    public function renderEnd(){
        return '</th>';
    }
}